package com.sc.nft.controller;

import com.sc.nft.annotation.SysMemberLogin;
import com.sc.nft.annotation.UserLogin;
import com.sc.nft.controller.request.*;
import com.sc.nft.dao.MallCategoryDao;
import com.sc.nft.dao.MallHotSaleActivityDao;
import com.sc.nft.entity.dto.PreferenceActivityDTO;
import com.sc.nft.entity.dto.SimpleCategoryDTO;
import com.sc.nft.entity.vo.mall.*;
import com.sc.nft.exception.GlobalException;
import com.sc.nft.feign.WxMiniProfitTemplateClient;
import com.sc.nft.pool.UserPool;
import com.sc.nft.service.MallActivityService;
import com.sc.nft.service.MallRecommendService;
import com.sc.nft.sup.PageRequest;
import com.sc.nft.sup.PageResult;
import com.sc.nft.sup.Result;
import com.sc.nft.vo.profittemplate.ProfitTemplateWebGoodsPageReq;
import com.sc.nft.vo.profittemplate.ProfitTemplateWebGoodsPageVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.List;

/**
 * 服务控制器
 *
 * @author 张翔宇
 * @since 2022-06-02 01:07:23
 */
@Slf4j
@RequiredArgsConstructor
@RestController
@RequestMapping("/ipMall/product")
@Api(tags ="IP商城商品")
public class IPMallProductController {

    private final MallRecommendService recommendService;
    private final MallCategoryDao mallCategoryDao;
    private final MallActivityService mallActivityService;
    private final MallHotSaleActivityDao mallHotSaleActivityDao;
    private final WxMiniProfitTemplateClient wxMiniProfitTemplateClient;


    @ApiOperation(value = "推荐商品列表", notes = "推荐商品列表", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/recommendProductPage", produces = MediaType.APPLICATION_JSON_VALUE)
    public PageResult<RecommendActivityPageVO> recommendProductPage(@Valid @RequestBody RecommendProductRequest request) throws GlobalException {
        return PageResult.success(recommendService.recommendPage( request.getActivityType(),request.getProductType(),request.getProductName(), request.toMp()));
    }

    @ApiOperation(value = "最近三张图", notes = "最近三张图", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/getThreeImage", produces = MediaType.APPLICATION_JSON_VALUE)
    public Result<List<String>> getThreeImage()  {
        return Result.success(mallActivityService.getThreeImage());
    }

    @ApiOperation(value = "活动列表", notes = "活动列表", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/activityPage", produces = MediaType.APPLICATION_JSON_VALUE)
    @UserLogin(required = false)
    public PageResult<ActivityPageVO> activityPage(@Valid @RequestBody ProductRequest request) throws GlobalException {
        return PageResult.success(mallActivityService.activityPage(request.getDaoId(),request.getCategoryId(), request.getActivityType(),request.getProductType(),request.getProductName(),request.getPage(),request.getIsSaas(),request.getShowMiniMall()));
    }

    @ApiOperation(value = "全部分类", notes = "全部分类", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/allCategories", produces = MediaType.APPLICATION_JSON_VALUE)
    @UserLogin(required = false)
    public PageResult<ActivityPageVO> allCategories(@Valid @RequestBody AllCategoriesRequest request) throws GlobalException {
        return PageResult.success(mallActivityService.allCategories(request.getDaoId(),request.getCategoryId(), request.getActivityType(),request.getProductType(),request.getProductName(),request.toMp(),request.getSort(),request.getShowMiniMall()));
    }

    @ApiOperation(value = "商品详情", notes = "商品详情", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/detail", produces = MediaType.APPLICATION_JSON_VALUE)
    @UserLogin(required = false)
    public Result<ActivityDetailVO> detail(@Valid @RequestBody ProductDetailRequest request) throws GlobalException {
        return Result.success(mallActivityService.activityDetail(UserPool.getUser(),request.getId(),request.getShareTeamId(),request.getExchangeForActivity()));
    }

    @ApiOperation(value = "商品详情V2", notes = "商品详情V2", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/detailV2", produces = MediaType.APPLICATION_JSON_VALUE)
    @UserLogin(required = false)
    public Result<ActivityDetailV2VO> detailV2(@Valid @RequestBody ProductDetailRequest request) throws GlobalException {
        return Result.success(mallActivityService.activityDetailV2(UserPool.getUser(),request.getId(),request.getShareTeamId(),request.getExchangeForActivity()));
    }

    @ApiOperation(value = "分类列表", notes = "分类列表", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/categoryList", produces = MediaType.APPLICATION_JSON_VALUE)
    @UserLogin(required = false)
    public Result<List<SimpleCategoryDTO>> productValuation(@Valid @RequestBody IdRequest request) throws GlobalException {
        return Result.successColl(mallCategoryDao.getMallCategoryList(request.getId()),SimpleCategoryDTO.class);
    }

    @ApiOperation(value = "热卖商品", notes = "首页-热卖商品", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/hotSaleProductPage", produces = MediaType.APPLICATION_JSON_VALUE)
    public PageResult<HotSaleActivityPageVO> hotSaleProductPage(@Valid @RequestBody HotSalePageRequest request) throws GlobalException {
        return PageResult.success(mallActivityService.hotSaleProductPage(request.getProductName(),request.getHotSaleSort(),request.toMp()));
    }

    @ApiOperation(value = "特价商品", notes = "特价商品", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/bargainPriceProductPage", produces = MediaType.APPLICATION_JSON_VALUE)
    public PageResult<BargainPriceProductPageVO> bargainPriceProductPage(@Valid @RequestBody BargainPriceProductPageRequest request) throws GlobalException {
        return PageResult.success(mallActivityService.bargainPriceProductPage(request.getProductName(), request.getBargainPriceSort(), request.toMp(),request.getIsSaas()));
    }

    @ApiOperation(value = "分类商品列表", notes = "分类商品列表", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/categoryProductPage", produces = MediaType.APPLICATION_JSON_VALUE)
    public PageResult<CategoryProductPageVO> categoryProductPage(@Valid @RequestBody CategoryProductPageRequest request) throws GlobalException {
        return PageResult.success(mallActivityService.categoryProductPage(request.getId(),request.getProductName(), request.getSort(),request.getIsVirtual(),request.toMp(),request.getIsSaas(),request.getShowMiniMall()));
    }

    @ApiOperation(value = "新分类列表", notes = "新分类列表", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/newCategoryList", produces = MediaType.APPLICATION_JSON_VALUE)
    @UserLogin(required = false)
    public Result<List<SimpleCategoryDTO>> newCategoryList() throws GlobalException {
        return Result.successColl(mallCategoryDao.newCategoryList(false),SimpleCategoryDTO.class);
    }

    @ApiOperation(value = "虚拟分类列表", notes = "虚拟分类列表", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/virtualCategoryList", produces = MediaType.APPLICATION_JSON_VALUE)
    @UserLogin(required = false)
    public Result<List<SimpleCategoryDTO>> virtualCategoryList() throws GlobalException {
        return Result.successColl(mallCategoryDao.newCategoryList(true),SimpleCategoryDTO.class);
    }

    @ApiOperation(value = "好物优选", notes = "好物优选", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/preferenceProductPage", produces = MediaType.APPLICATION_JSON_VALUE)
    @UserLogin
    public PageResult<PreferenceActivityDTO> preferenceProductPage(@Valid @RequestBody PageRequest pageRequest) throws GlobalException {
        return PageResult.success(mallActivityService.preferenceProductPage(pageRequest.toMp()));
    }



    @ApiOperation(value = "小程序商品详情", notes = "小程序商品详情商品详情", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/miniMall/detail", produces = MediaType.APPLICATION_JSON_VALUE)
    public Result<ActivityMiniMallDetailVO> miniMallDetail(@Valid @RequestBody MiniMallProductDetailRequest request) throws GlobalException {
        return Result.success(mallActivityService.miniMallDetail(request.getId(),request.getOpenId()));
    }


    @ApiOperation(value = "小程序分销专区", notes = "小程序商品详情商品详情", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/miniMall/distribution", produces = MediaType.APPLICATION_JSON_VALUE)
    @UserLogin(required = false)
    public PageResult<ProfitTemplateWebGoodsPageVO> miniMallDistribution(@RequestBody ProfitTemplateWebGoodsPageReq request) {
        return wxMiniProfitTemplateClient.webGoods(request);
    }

    @ApiOperation(value = "小程序新分类列表", notes = "新分类列表", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/miniMall/newCategoryList", produces = MediaType.APPLICATION_JSON_VALUE)
    public Result<List<SimpleCategoryDTO>> miniMallNewCategoryList() throws GlobalException {
        return Result.successColl(mallCategoryDao.newCategoryList(false),SimpleCategoryDTO.class);
    }


    @ApiOperation(value = "小程序分类商品列表", notes = "分类商品列表", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/miniMall/categoryProductPage", produces = MediaType.APPLICATION_JSON_VALUE)
    public PageResult<CategoryProductPageVO> miniMallCategoryProductPage(@Valid @RequestBody CategoryProductPageRequest request) throws GlobalException {
        return PageResult.success(mallActivityService.miniMallCategoryProductPage(request.getId(),request.getProductName(), request.getSort(),request.getIsVirtual(),request.toMp(),request.getIsSaas(),request.getShowMiniMall()));
    }

}